package com.pxst.aop;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import com.pxst.entity.LoginUser;
import com.pxst.exception.LoginException;
import com.pxst.utils.SecurityFrameworkUtils;

import lombok.extern.slf4j.Slf4j;

/** 
 * 添加PreAuthorize注解的需要登录
* @author yangxy
* @version 创建时间：2023年7月26日 下午4:25:43 
*/
@Slf4j
@Aspect
@Order(0)
@Component
public class PreAuthorizeAop {
	
//	@Pointcut("@annotation(org.springframework.security.access.prepost.PreAuthorize)")
//	public void aopPoint() {
//	}
	
	@Around("@annotation(org.springframework.security.access.prepost.PreAuthorize)")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
		LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
		if(ObjectUtils.isEmpty(loginUser)) {
			throw new LoginException("未登录");
		}
        return joinPoint.proceed();
    }
}
